package com.nineclock.system.easyexcel;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.nineclock.system.service.SysCompanyUserService;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 黑马程序员
 * @Company http://www.ithiema.com
 * @Version 1.0
 */
public class MemberParseListener extends AnalysisEventListener<ExcelMember> {

    private SysCompanyUserService companyUserService;

    public MemberParseListener(SysCompanyUserService companyUserService){
        this.companyUserService = companyUserService;
    }


    private List<ExcelMember> list = new ArrayList<>();

    @Override
    public void invoke(ExcelMember data, AnalysisContext context) {
        //把每一行对应的对象添加到集合中
        list.add(data);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        //读取完成后 执行
        companyUserService.importData(list);
    }
}
